/*
 * Copyright (c) 2024 endless-sky
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PERIPHERAL_INIT_H__
#define PERIPHERAL_INIT_H__

#include <mutex>

namespace El {
namespace Peripheral {

/**
 * @brief 外设服务管理类（单例模式）
 * 统一管理所有外设组件的生命周期，包括串口管理器和开关控制器
 */
class PeripheralService {
public:
    /**
     * @brief 获取单例实例
     * @return PeripheralService& 单例实例引用
     */
    static PeripheralService &GetInstance();

    /**
     * @brief 启动外设服务
     * 初始化所有外设组件
     * @return bool true=成功，false=失败
     */
    bool Start();

    /**
     * @brief 停止外设服务
     * 释放所有外设组件资源
     * @return bool true=成功，false=失败
     */
    bool Stop();

    /**
     * @brief 检查外设服务是否已启动
     * @return bool true=已启动，false=未启动
     */
    bool IsStarted() const;

private:
    PeripheralService();
    ~PeripheralService();

    // 禁止拷贝构造和赋值
    PeripheralService(const PeripheralService&) = delete;
    PeripheralService& operator=(const PeripheralService&) = delete;

private:
    mutable std::mutex mutex_;
    bool started_;
};

} // namespace Peripheral
} // namespace El

#endif // PERIPHERAL_INIT_H__